package com.longcai.piaojia.conn;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/11/10.
 */
@HttpInlet(Conn.SIGN_RECORD)
public class SignRecordGet extends BaseAsyGet<SignRecordGet.SignRecordEntity> {

    public String user_id;
    public int page;

    public SignRecordGet(AsyCallBack<SignRecordEntity> asyCallBack) {
        super(asyCallBack);
    }

    @Override
    protected SignRecordEntity parser(JSONObject object) throws Exception {

        TOAST = object.optString("message");

        if (object.optInt("code") == 200) {

            SignRecordEntity signRecordEntity = new SignRecordEntity();

            JSONObject entityObject = object.optJSONObject("data");

            signRecordEntity.current_page = entityObject.optInt("current_page");
            signRecordEntity.per_page = entityObject.optInt("per_page");
            signRecordEntity.total = entityObject.optInt("total");

            JSONArray array = entityObject.optJSONArray("data");

            for (int i = 0; i < array.length(); i++) {

                JSONObject recordObject = array.optJSONObject(i);

                SingRecord singRecord = new SingRecord();

                singRecord._id = recordObject.optString("_id");
                singRecord.id = recordObject.optString("id");
                singRecord.user_id = recordObject.optString("user_id");
                singRecord.phone = recordObject.optString("phone");
                singRecord.type = recordObject.optString("type");
                singRecord.money = recordObject.optString("money");
                singRecord.posttime = recordObject.optString("posttime");
                singRecord.times = recordObject.optString("times");
                singRecord.info = recordObject.optString("info");

                signRecordEntity.signRecordLists.add(singRecord);

            }

            return signRecordEntity;

        }


        return null;
    }

    public static class SignRecordEntity {

        public int total, per_page, current_page;

        public List<SingRecord> signRecordLists = new ArrayList();

    }

    public static class SingRecord {

        public String _id, id, user_id, phone, type, money, posttime, times, info;

    }

}
